package com.sx.jys.ui.vm

import com.blankj.utilcode.util.CollectionUtils
import com.sx.jys.app.net.HttpRequestCoroutine
import com.sx.jys.app.net.bean.OrderBean
import com.sx.jys.app.until.MutableLiveListData
import com.sx.jys.app.until.request2
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.livedata.BooleanLiveData

class CkDetailVm : BaseViewModel() {
    lateinit var code: String
    lateinit var status: String
    lateinit var openTime: String

    val listLiveData = MutableLiveListData<OrderBean>()

    val uiState = UIStateChange()

    inner class UIStateChange {
        val refreshEvent = BooleanLiveData()
        val loadMoreEvent = BooleanLiveData()
    }

    fun reqDetailList(page: Int) {
        request2({ HttpRequestCoroutine.ckSecondList(code, openTime,page, status) }, {
            if (page == 1) {
                listLiveData.value = it.records
            } else {
                listLiveData.addData(it.records)
            }
            uiState.refreshEvent.postValue(true)
            uiState.loadMoreEvent.postValue(!CollectionUtils.isEmpty(it.records))
        }, isShowDialog = page == 1)


    }
}